import cv2
import imageio

def img_capture(video):
	cap=cv2.VideoCapture(video)#创建视频工程
	num=0
	ret,frame=cap.read()
	while ret and num <= 1296:#循环保存变身过程的帧
		if num > 1056 and num % 3 ==0:
			cv2.imwrite("img%d.png" % num, frame)#保存
			print("[I] Get %d Frame!" % num)
		ret, frame=cap.read()
		num+=1#等同于num=num+1

def gif_save():
	print("[I] Gif saveing...")
	images=[]
	for num in range(1059,1297,3):
		img=imageio.imread("img%d.png" % num)
		images.append(img)#加入列表
		print("[I] Saved %d ..." % num)
	print("[I] Outputing gif...")
	imageio.mimsave("codemao2017.gif",images,fps=8)#输出gif

img_capture("codemao2017.mp4")
gif_save()
exit=input("[I] Done!")